import base64

import requests
import json

import urllib3
from jsonpath import jsonpath
from dataclasses import dataclass
from typing import Optional


@dataclass
class ValidataModal:
    data: str
    result: str
    description: Optional[str] = None

urllib3.disable_warnings()
session = requests.Session()
from jsonschema import validate

schema = {
    "type": "object",
    "properties": {
        "data": {"type": "null | string"},
        "description": {"type": "null | string",},
        "result": {"type": "string"}

    },
}
def enconde_bs64(data):
    data = json.dumps(data, indent=4, ensure_ascii=True)
    encode64 = base64.b64encode(data.encode('utf-8'))
    return encode64.decode('utf-8')

def decode64_str(data):
    decode64 = base64.b64decode(data)
    decode64_str = decode64.decode('utf-8')
    return decode64_str


url = "https://192.168.10.146/microServiceUser/responseEncode/requestDecode/login"

payload = {
    "type": 0,
    "sourcePlatform": "RETONE_FIT",
    "password": "cc1234",
    "loginObject": "tester9999"
}

headers = {
   'Content-Type': 'application/json'
}

response = session.post(url, headers=headers, json=enconde_bs64(payload), verify=False, timeout=12)
res = response.json()
validate_result = ValidataModal(res['data'], res['result'], res['description'])
print(validate_result)
# print(res)
# validate(instance=res, schema=schema)
# print(res)
# data = jsonpath(res, "$.*")
# print(data)

# print(response.text)
# print(res['result'],"type = ",type(res['result']))